package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domain.User;
import com.tanhua.model.vo.HuanXinUserVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Administrator
 */
@DubboService
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String mobile) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getMobile, mobile));
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public List<User> findAll() {
        List<User> users = userMapper.selectList(Wrappers.emptyWrapper());
        return users;
    }

    @Override
    public HuanXinUserVo findHuanXinUser(Long userId) {
        User user = userMapper.selectById(userId);
        if (user == null) {
            return null;
        }
        HuanXinUserVo huanXinUserVo = new HuanXinUserVo();
        huanXinUserVo.setUsername(user.getHxUser());
        huanXinUserVo.setPassword(user.getHxPassword());
        return huanXinUserVo;
    }
}